package com.psj.controller;

import com.github.pagehelper.PageInfo;
import com.psj.aspect.MyLog;
import com.psj.bean.Main;
import com.psj.bean.Place;
import com.psj.bean.Stadium;
import com.psj.bean.Type;
import com.psj.service.MainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class MainController {

    @Autowired
    MainService mainService;

    @RequestMapping("list")
    public String list(Main main, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "3") Integer pageSize, Model model){
        PageInfo<Main> info = mainService.list(main,pageNum,pageSize);
        model.addAttribute("pg",info);
        model.addAttribute("main",main);
        return "list";
    }

    //下拉框
    @RequestMapping("listStadium")
    @ResponseBody
    public List<Stadium> listStadium(){
        return mainService.listStadium();
    }
    @RequestMapping("listType")
    @ResponseBody
    public List<Type> listType(){
        return mainService.listType();
    }
    @RequestMapping("listPlace")
    @ResponseBody
    public List<Place> listPlace(){
        return mainService.listPlace();
    }

    @RequestMapping("toAdd")
    public String toAdd(Model model){
        model.addAttribute("main",new Main());
        return "add";
    }

    @MyLog
    @RequestMapping("add")
    public String add(Main main,Model model){
        int i = mainService.add(main);
        return "redirect:list";
    }

    @RequestMapping("toBarEchars")
    public String toBarEchars(){
        return "barEchars";
    }

    @RequestMapping("getCallTj")
    @ResponseBody
    public List<Main> getCallTj(){
        return mainService.getCallTj();
    }

}

